package com.snack.shop.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.snack.shop.common.Result;
import com.snack.shop.dto.HotProductDTO;
import com.snack.shop.dto.MerchantStatsDTO;
import com.snack.shop.service.MerchantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商家管理控制器
 */
@Tag(name = "商家管理")
@RestController
@RequestMapping("/merchant")
@RequiredArgsConstructor
@SaCheckRole("merchant")
public class MerchantController {

    private final MerchantService merchantService;

    @Operation(summary = "获取商家统计数据")
    @GetMapping("/stats")
    public Result<MerchantStatsDTO> getStats(
        @Parameter(description = "时间范围: today/week/month/all") @RequestParam(defaultValue = "today") String timeRange
    ) {
        MerchantStatsDTO stats = merchantService.getStats(timeRange);
        return Result.success(stats);
    }

    @Operation(summary = "获取热销商品TOP10")
    @GetMapping("/hot-products")
    public Result<List<HotProductDTO>> getHotProducts(
        @Parameter(description = "时间范围: today/week/month/all") @RequestParam(defaultValue = "month") String timeRange,
        @Parameter(description = "返回数量") @RequestParam(defaultValue = "10") Integer limit
    ) {
        List<HotProductDTO> hotProducts = merchantService.getHotProducts(timeRange, limit);
        return Result.success(hotProducts);
    }
}

